<!--
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-06-26 08:47:22
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-07-22 11:22:38
 * @FilePath: \linePatrol\vue-element-plus-admin\src\views\GIS\OneMap\components\Point.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="tsx">
import { ref, unref, reactive, h, computed } from 'vue'
import { Table } from '@/components/Table'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { useTable } from '@/hooks/web/useTable'
import GisInfoApi from '@/api/gis/gisMap'
import { Search } from '@/components/Search'
import { useI18n } from 'vue-i18n'
import { useEquipStore } from '@/store/modules/equip'
import { ElTag } from 'element-plus'
import { useDictStore } from '@/store/modules/dictData'
import { useDeptStore } from '@/store/modules/dept'
import { usePatrolGroupStore } from '@/store/modules/PlanGroupStore'
const { t } = useI18n()
const EquipStore = useEquipStore()
const DictStore = useDictStore()
const DeptStore = useDeptStore()
const GroupStore = usePatrolGroupStore()
if (EquipStore.getProducerLedger.length == 0) {
  EquipStore.setProducerLedger()
} //获取厂商列表
//厂商列表
const ProducerList = computed(() => {
  return EquipStore.getProducerLedger
})
DictStore.setDict('fac_y_or_n') //是否
DictStore.setDict('red_type') //红线字典
DictStore.setDict('fac_dict_type') //设施类型
DictStore.setDict('fac_state') //状态字典
DictStore.setDict('mc_material') //井盖材质字典
//执行用户列表
const UserList = computed(() => {
  return GroupStore.getUserListAll
})
const crudSchemas = reactive<CrudSchema[]>([
  {
    field: 'selection',
    type: 'selection',
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    fixed: 'left'
  },
  {
    field: 'index',
    label: t('tableDemo.index'),
    type: 'index',
    fixed: 'left',
    form: {
      hidden: true
    },
    search: {
      hidden: true
    }
  },
  {
    field: 'facName',
    label: t('设施名称'),
    width: 100,
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    },
    search: {
      hidden: false,
      component: 'Input',
      componentProps: {
        placeholder: '设施名称'
      }
    }
  },
  {
    field: 'facState',
    label: t('设施状态'),
    width: 100,
    formatter: (_: Recordable, __: any, cellValue: string) => {
      return DictStore.$state.fac_state?.map((item) => {
        if (item.dictValue == cellValue) {
          return h(ElTag, { type: item.listClass }, () => item.dictLabel)
        }
      })
    },
    search: {
      hidden: false,
      component: 'Select',
      componentProps: {
        placeholder: '设施状态',
        options: DictStore.$state.fac_state?.map((item) => {
          return {
            label: item.dictLabel,
            value: item.dictValue
          }
        })
      }
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'facDictType',
    label: t('设施类型'),
    width: 150,
    formatter: (_: Recordable, __: any, cellValue: string) => {
      return DictStore.$state.fac_dict_type?.map((item) => {
        if (item.dictValue == cellValue) {
          return item.dictLabel
        }
      })
    },
    search: {
      hidden: false,
      component: 'Select',
      componentProps: {
        placeholder: '设施类型',
        options: DictStore.$state.fac_dict_type?.map((item) => {
          return {
            label: item.dictLabel,
            value: item.dictValue
          }
        })
      }
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'address',
    label: t('详细地址'),
    width: 150,
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'redType',
    label: t('红线'),
    width: 150,
    formatter: (_: Recordable, __: any, cellValue: string) => {
      return DictStore.$state.red_type?.map((item) => {
        if (item.dictValue == cellValue) {
          return item.dictLabel
        }
      })
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    },
    search: {
      hidden: true
    }
  },
  {
    field: 'producerUuid',
    label: t('厂商'),
    width: 150,
    formatter: (_: Recordable, __: any, cellValue: string) => {
      return ProducerList.value.map((item) => {
        if (item.uuid == cellValue) {
          return item.producerName
        }
      })
    },
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'coId',
    label: t('所属公司'),
    width: 150,
    formatter: (_: Recordable, __: any, cellValue: number) => {
      if (cellValue !== undefined && cellValue) {
        return DeptStore.getDeptName(cellValue)[0]?.deptName
      }
    },
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'isDeadFac',
    label: t('是否截止点设施'),
    width: 150,
    formatter: (_: Recordable, __: any, cellValue: string) => {
      return DictStore.$state.fac_y_or_n?.map((item) => {
        if (item.dictValue == cellValue) {
          return item.dictLabel
        }
      })
    },
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'isCoAs',
    label: t('是否公司资产'),
    width: 150,
    formatter: (_: Recordable, __: any, cellValue: string) => {
      return DictStore.$state.fac_y_or_n?.map((item) => {
        if (item.dictValue == cellValue) {
          return item.dictLabel
        }
      })
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    },
    search: {
      hidden: true
    }
  },
  {
    field: 'qrCode',
    label: t('二维码编号'),
    width: 150,
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },

  {
    field: 'facOutModel',
    label: t('设施型号'),
    width: 150,
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'userId',
    label: t('责任人'),
    formatter: (_: Recordable, __: any, cellValue: number) => {
      return UserList.value.map((item) => {
        if (item.userId == cellValue) {
          return item.userName
        }
      })
    },
    width: 150,
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'facOutNo',
    label: t('出厂编号'),
    width: 150,
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  },
  {
    field: 'factoryStation',
    label: t('所属厂站'),
    width: 150,
    search: {
      hidden: true
    },
    form: {
      hidden: true
    },
    detail: {
      hidden: true
    }
  }
])
const { tableRegister, tableState, tableMethods } = useTable({
  fetchDataApi: async () => {
    const { currentPage, pageSize } = tableState
    const res = await GisInfoApi.GetPipePointList({
      pageNum: unref(currentPage),
      pageSize: unref(pageSize),
      ...unref(searchParams)
    })
    return {
      list: res.rows,
      total: res.total
    }
  },
  fetchDelApi: async () => {
    return true
  }
})
const { loading, dataList, total, currentPage, pageSize } = tableState
const { getList } = tableMethods
const searchParams = ref({})
const setSearchParams = (params: any) => {
  currentPage.value = 1
  searchParams.value = params
  getList()
}
const { allSchemas } = useCrudSchemas(crudSchemas)
</script>
<template>
  <Search :schema="allSchemas.searchSchema" @reset="setSearchParams" @search="setSearchParams" />
  <Table
    v-model:pageSize="pageSize"
    v-model:currentPage="currentPage"
    :columns="allSchemas.tableColumns"
    :data="dataList"
    row-key="uuid"
    :loading="loading"
    :pagination="{
      total: total
    }"
    @register="tableRegister"
  />
</template>
<style scope lang="less">
// :deep(管线类型)
</style>
